package com.example.db.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.blankj.utilcode.util.GsonUtils

/**
 * 用户信息的数据库实体对象
 */

@Entity(tableName = "user_info_table")
@TypeConverters(CustomTypeConverters::class)
data class UserInfoEntity(

    @PrimaryKey
    val userId: Int,

    @ColumnInfo(name = "name")
    val userName: String,

    @ColumnInfo(name = "nick")
    val nickName: String,

    )

/**
 * 自定义类型转换器
 */
class CustomTypeConverters{

    @TypeConverter
    fun arrayListToString(list: ArrayList<String>): String{
        return GsonUtils.toJson(list)
    }

    @TypeConverter
    fun stringToArrayList(json: String): ArrayList<String>{
        return GsonUtils.fromJson(json, ArrayList::class.java) as ArrayList<String>
    }


}